package com.github.jspxnet.worktask.table;

import com.github.jspxnet.enums.BoolEnumType;
import com.github.jspxnet.sober.annotation.Column;
import com.github.jspxnet.sober.annotation.Id;
import com.github.jspxnet.sober.annotation.Nexus;
import com.github.jspxnet.sober.annotation.Table;
import com.github.jspxnet.sober.enums.MappingType;
import com.github.jspxnet.utils.StringUtil;
import com.github.jspxnet.worktask.model.enums.*;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jspx.net
 *
 * author: chenYuan
 * date: 2020/9/8 22:22
 * description: 配置的节点任务
 *
 **/
@Table(name = "jwf_work_node", caption = "流程节点")
@Data
public class ConfFlowNode implements Serializable  {
    @Id
    @Column(caption = "ID", notNull = true)
    private long id = 0;

    @Column(caption = "命名空间", length = 50, dataType = "isLengthBetween(1,50)")
    private String namespace = StringUtil.empty;

    @Column(caption = "流程编号", length = 32, notNull = true)
    private String flowNo = StringUtil.empty;

    //不能等于本节点
    @Column(caption = "所属节点ID", length = 32, notNull = true)
    private String nodeId = StringUtil.empty;

    @Column(caption = "节点名称", length = 32, notNull = true)
    private String title = StringUtil.empty;

    //加签功能, 网关节点,使用网关里边的分支映射表
    //当为合并节点的时候这里是多个
    @Column(caption = "父ID", length = 1000, notNull = true)
    private String parentNodeId = StringUtil.empty;

    @Column(caption = "节点类型", length = 2,enumType = FlowNodeEnumType.class , notNull = true,input = "select")
    private int flowNodeType = FlowNodeEnumType.START.getValue();

    //标识下一步是否有分支,或者合并
    @Column(caption = "网关类型", length = 2,enumType = GatewayEnumType.class , notNull = true,input = "select")
    private int gatWayType = GatewayEnumType.NONE.getValue();

    @Nexus(mapping = MappingType.OneToOne, field = "nodeId", targetField = "nodeId",where = "flowNodeType==2", term = "flowNo:eq[${flowNo}];namespace:eq[${namespace}]",targetEntity = ConfFlowJob.class, save = true, update = true,chain = true)
    private ConfFlowJob confFlowJob = null;

    @Column(caption = "网关分支条件", length = 1000)
    private String wayScript = null;

    @Column(caption = "合并到节点", length = 60, notNull = true)
    private String joinNodeId = StringUtil.empty;

    //json格式保存
    @Column(caption = "用户id列表", length = 10000)
    private String users = StringUtil.empty;

    //单个节点的特殊配置,-1 表示没有特殊配置是用 流程默认配置
    @Column(caption = "限时办理", length = 2,enumType = BoolEnumType.class , notNull = true,input = "radio")
    private int dueType = BoolEnumType.NO.getValue();

    @Column(caption = "时间格式", length = 2,enumType = DueDateFormatEnumType.class , notNull = true,input = "select")
    private int dueDateFormat = DueDateFormatEnumType.CRON.getValue();

    /**
     R3/2004-05-06T130000+08/P0Y6M5DT3H0M0S。
     以1年2个月为循环间隔，无限次循环，最后循环终止于2025年1    月1日，可表示为R/P1Y2M/2025-01-01
     */
    //到期日期
    @Column(caption = "定时表达式", length = 250)
    private String dueDateExp = StringUtil.empty;

    //超时到达的节点,超时到那个节点
    @Column(caption = "超时节点ID", length = 32, notNull = true)
    private String dueNodeId = StringUtil.empty;

    @Column(caption = "排序", option = "0:默认;2:固顶;4:置顶;8:结对置顶;-1:下沉", notNull = true,input = "select")
    private int sortType = 0;
}
